﻿using K9Nano.Application.Editions;
using K9Nano.Caching;
using K9Nano.Dependency;
using K9Nano.Events.Entity;

namespace K9Nano.Application.Features.Events
{
    public class TenantFeatureSettingChangedEventHandler : IEntityChangedEventHandler<TenantFeatureSetting>, ISingletonDependency
    {
        private readonly ITypedCache<TenantFeatureCacheItem> _cache;

        public TenantFeatureSettingChangedEventHandler(ITypedCache<TenantFeatureCacheItem> cache)
        {
            _cache = cache;
        }

        public void HandleEvent(EntityChangedEventData<TenantFeatureSetting> eventData)
        {
            if (eventData.Entity.IsTransient()) return;
            _cache.Remove(eventData.Entity.TenantId.Value.ToString());
        }
    }
}